//
//  BaseViewController.swift
//  WeiBo
//
//  Created by iris on 16/3/14.
//  Copyright © 2016年 陈真真. All rights reserved.
//

import UIKit

class BaseViewController: UITableViewController {

    // MARK:- 懒加载
    lazy var visitorView : VisitorView = VisitorView.visitorView()
    
    // MARK:- 属性
    var isLogin : Bool = false
    
    // MARK:- 系统回调函数
    override func loadView() {
        isLogin ? super.loadView() : setupVisitorView()
    }
}

extension BaseViewController {
    /// 加载访客视图
    private func setupVisitorView() {
        view = visitorView
        
        // 2.添加导航栏左右的item
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: .Plain, target: self, action: "registerBtnClick")
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: .Plain, target: self, action: "loginBtnClick")
        
        // 3.监听访客视图中注册和登录按钮的点击
        visitorView.registerBtn.addTarget(self, action: "registerBtnClick", forControlEvents: .TouchUpInside)
        visitorView.loginBtn.addTarget(self, action: "loginBtnClick", forControlEvents: .TouchUpInside)
    }
}

// MARK:- 按钮的点击事件
extension BaseViewController {
    @objc private func registerBtnClick() {
        print("registerBtnClick")
    }
    
    @objc private func loginBtnClick() {
        print("loginBtnClick")
    }
}